<?php

namespace app\admin\model\sum;

use app\admin\model\sum\Common;
use app\admin\model\sum\Config as SumConfig;

class Slides extends Common
{

    // 表名
    protected $name = 'sum_slides';

    // 追加属性
    protected $append = [
        'lang_text',
        'status_text',
        'image_url',
        'bg_image_url',
        'slug_text'
    ];


    // 语言列表
    public function langList()
    {
        $configs = SumConfig::getConfigs('language.option', false);
        $data=[];
        foreach ($configs as $cv){
            $data[$cv['slug']]=$cv['title'];
        }
        return $data;
    }

    // 标识列表
    public function slugList()
    {
        return [
            'home'       => '首页轮播',
        ];
    }

    /**
     * 获取器
     * @param string $value
     * @param array $data
     * @return string
     */
    public function getSlugTextAttr($value, $data)
    {
        $value = $value ?: ($data['slug'] ?? null);

        $list = $this->slugList();
        return isset($list[$value]) ? $list[$value] : '';
    }
    /**
     * 获取器
     * @param string $value
     * @param array $data
     * @return string
     */
    public function getLangTextAttr($value, $data)
    {
        $value = $value ?: ($data['lang'] ?? null);

        $list = $this->langList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getImageUrlAttr($value, $data)
    {
        $image_url = $data['image']?cdnurl($data['image'], true):'';
        return $image_url;
    }
    public function getBgImageUrlAttr($value, $data)
    {
        $image_url = $data['bg_image']?cdnurl($data['bg_image'], true):'';
        return $image_url;
    }
}
